package com.itheima.day10.myStream.test1;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;

public class Demo {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>(List.of("张小三","张三","张小凡","张帅","张帅帅"));
        LinkedList<String> ll = new LinkedList<>();
        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            if(!s.startsWith("张"))
                continue;
            if(s.length() == 3)
                ll.add(s);
        }
        System.out.println(ll);

        list.stream().filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                if(s.startsWith("张"))
                return true;
                return false;
            }
        }).filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                if(s.length() == 3)
                    return true;
                return false;
            }
        }).forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

        list.stream().filter( (String s) -> { return s.startsWith("张");}
        ).filter((String s) -> {return s.length() == 3;}
        ).forEach((String s) -> { System.out.println(s); });
    }
}
